// stores/websocket.ts
import { defineStore } from 'pinia';
import WebSocketService from '@/WebSocket/websocket';

export const useWebSocketStore = defineStore({
  id: 'websocket',
  state: () => ({
    messages: [] as string[], // 存储消息
    connected: false,
  }),
  actions: {
    connect() {
      WebSocketService.connect();
      this.connected = true;
    },
    sendMessage(message: string) {
      WebSocketService.send(message);
    },
    closeConnection() {
      WebSocketService.close();
      this.connected = false;
    },
    addMessage(message: string) {
      this.messages.push(message);
    },
  },
});
